﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Emgu.CV;
using Emgu.Util;
using System.Drawing;
using Emgu.CV.UI;
using System.Threading;
using System.Windows.Forms;

namespace ObjectTracking
{
    class Program
    {
        static void Main(string[] args)
        {
            Capture capture = new Capture();
            if (capture == null) 
            {
                Console.WriteLine("No camera found.");
                return;
            }
            //CvInvoke.cvNamedWindow("C");
            //CvInvoke.cvNamedWindow("Tresholded");
            IntPtr? imgScribble = null;
            ImageViewer iw = new ImageViewer();
            iw.ShowDialog();
            Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
            {  //run this until application closed (close button click on image viewer)
                iw.Image = capture.QueryFrame(); //draw the image obtained from camera
            });

            //while (true)
            //{
            //    Thread.Sleep(100);
            //    iw.Image = capture.QueryFrame();
                
                //IntPtr frame = image.Ptr;
                //if (frame == null)
                //{
                //    break;
                //}

                //if (imgScribble == null) 
                //{
                //    imgScribble = CvInvoke.cvCreateImage(CvInvoke.cvGetSize(frame), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 3);
                //}
                //IntPtr imgTresholded = ColorTracking.GetTresholdedImage(frame);
                //CvInvoke.cvShowImage("C", image.Ptr);
                //webcamWindow.SetImage((Image)capture.QueryFrame().Bitmap);
                //CvInvoke.cvShowImage("Tresholded", frame);
            //}
            
        }
    }
}
